<template>
  <div class="page-container dash-container">
    <el-carousel :interval="2000" type="card" height="370px">
      <el-carousel-item v-for="item in myDashArr.data" :key="item">
        <img
          :src="item?.src"
          :style="{
            width: '100%',
            height: '100%',
          }"
        />
      </el-carousel-item>
    </el-carousel>
    <h1 ref="titlecontainer" class="dashboard-title">欢迎来到我的个人空间管理系统</h1>
  </div>
</template>

<script setup lang="ts">
import { getDashBoard } from "@/api/dashboard";
import { ref, onMounted, reactive } from "vue";

interface IMyDashArr {
  data: { src: string }[];
}

// 绑定
const titlecontainer = ref();

// 数据定义
const myDashArr = reactive<IMyDashArr>({
  data: [],
});

// 动态显示
function setWidth(width: string) {
  titlecontainer.value.style.width = 0;
  titlecontainer.value.style.opacity = 1;
  titlecontainer.value.clientHeight;
  titlecontainer.value.style.transition = "5s";
  titlecontainer.value.style.width = width;
}

onMounted(() => {
  fetchData();
  const width = getComputedStyle(titlecontainer.value).width;
  setWidth(width);
});

// 数据请求
async function fetchData() {
  const res = await getDashBoard();
  console.log(res);
  if (res.code === 0) {
    myDashArr.data = res.data;
  }
}
</script>

<style lang="less" scoped>
.dashboard-title {
  text-align: center;
  color: #fff;
  text-shadow: -3px 3px #000, 3px -3px #000;
  width: 500px;
  margin: 0 auto;
  opacity: 0;
  white-space: nowrap;
  overflow: hidden;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
